package com.yhp.service.impl;

import com.fasterxml.jackson.core.util.InternCache;
import com.yhp.mapper.CategoryMapper;
import com.yhp.mapper.CategoryMapperCustom;
import com.yhp.pojo.Category;
import com.yhp.service.CategoryService;
import com.yhp.vo.CategoryVO;
import com.yhp.vo.ItemVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

import javax.script.ScriptEngine;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class CategoryServiceImpl implements CategoryService {
    @Autowired
    private CategoryMapper categoryMapper;

    @Autowired
    private CategoryMapperCustom categoryMapperCustom;

    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public List<Category> queryAllRootCats() {
        Example example = new Example(Category.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("type",1);
        List<Category> categories = categoryMapper.selectByExample(example);
        return categories;
    }

    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public List<CategoryVO> querySecondCats(Integer typeId) {
        List<CategoryVO> subCats = categoryMapperCustom.getSubCats(typeId);
        return subCats;
    }

    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public List<ItemVO> querySix(Integer rootId) {
        Map map=new HashMap<String, Integer>();
        map.put("rootId",rootId);
        List<ItemVO> itemVOList = categoryMapperCustom.getSix(map);
        return itemVOList;
    }
}
